package com.shop.loan.controller;

import com.shop.loan.annotation.LoginAuth;
import com.shop.loan.model.UserAddress;
import com.shop.loan.model.common.Constant;
import com.shop.loan.model.common.ResResult;
import com.shop.loan.model.vo.UserAddressVo;
import com.shop.loan.service.UserAddressService;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;

@Api(value = "用户收货地址管理", tags = "用户收货地址管理")
@RestController
@RequestMapping(Constant.appPrefex + "/address")
public class UserAddressController {

    @Resource
    UserAddressService addressService;

    @LoginAuth
    @PostMapping("/update")
    @ApiOperation(value = "修改/删除")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "地址id", dataType = "string", required = true),
            @ApiImplicitParam(name = "provinceName", value = "省份", dataType = "string", required = true),
            @ApiImplicitParam(name = "cityName", value = "城市", dataType = "string", required = true),
            @ApiImplicitParam(name = "countyName", value = "区/县", dataType = "string", required = true),
            @ApiImplicitParam(name = "detailInfo", value = "地址详情", dataType = "string", required = true),
            @ApiImplicitParam(name = "userName", value = "收货人", dataType = "string", required = true),
            @ApiImplicitParam(name = "userPhone", value = "电话号码", dataType = "string", required = true),
            @ApiImplicitParam(name = "isDelete", value = "是否删除   如果需要删除 传true", dataType = "boolean", required = true),
    })
    @ApiResponses({
            @ApiResponse(code = 1, message = "成功")
    })
    public ResResult update(@ApiIgnore UserAddressVo userAddressVo) {
        return addressService.update(userAddressVo);
    }

    @LoginAuth
    @PostMapping("/add")
    @ApiOperation(value = "新增地址")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "provinceName", value = "省份", dataType = "string", required = true),
            @ApiImplicitParam(name = "cityName", value = "城市", dataType = "string", required = true),
            @ApiImplicitParam(name = "countyName", value = "区/县", dataType = "string", required = true),
            @ApiImplicitParam(name = "detailInfo", value = "地址详情", dataType = "string", required = true),
            @ApiImplicitParam(name = "userName", value = "收货人", dataType = "string", required = true),
            @ApiImplicitParam(name = "userPhone", value = "电话号码", dataType = "string", required = true),
    })
    @ApiResponses({
            @ApiResponse(code = 1, message = "成功")
    })
    public ResResult add(@ApiIgnore UserAddressVo userAddressVo) {
        return addressService.add(userAddressVo);
    }


    @LoginAuth
    @PostMapping("/list")
    @ApiOperation(value = "地址列表")
    @ApiResponses({
            @ApiResponse(code = 1, message = "成功", response = UserAddress.class)
    })
    public ResResult list(@ApiIgnore UserAddressVo userAddressVo) {
        return addressService.list(userAddressVo);
    }

}
